class Solution {
public:
    int eraseOverlapIntervals(vector<vector<int>>& intervals)
    {
        sort(intervals.begin(), intervals.end(), [&](vector<int>a, vector<int>b) {
            return a[0] < b[0];
            });
        int ret = 0;
        int left = intervals[0][0];
        int right = intervals[0][1];
        for (int i = 1; i < intervals.size(); i++)
        {
            int a = intervals[i][0];
            int b = intervals[i][1];
            if (a < right)
            {
                ret++;
                right = min(right, b);
            }
            else
            {
                right = b;
            }
        }
        return ret;
    }
};